package net.aop.proxy;

import net.aop.aspect.MyAspect;
import net.aop.dao.CartDao;
import net.aop.dao.impl.CartDaoImplOne;
import net.zjitc.pojo.User;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class JdkProxy implements InvocationHandler {
    private CartDao cartDao;
    public Object createObject(CartDao cartDao){
        this.cartDao = cartDao;
        Class[] clazz = this.cartDao.getClass().getInterfaces();
        return Proxy.newProxyInstance(this.cartDao.getClass().getClassLoader(),clazz,this);
    }
    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        MyAspect myAspect = new MyAspect();
        myAspect.check_author();
        Object obj = method.invoke(this.cartDao, args);
        myAspect.log();
        return obj;
    }
}
